//
//  UserManageBaseViewModel.m
//  YIJU2.0HD
//
//  Created by 张金国 on 16/5/26.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "UserManageBaseViewModel.h"
#import "UserManage.h"
#import "CommonCustomer.h"
#import "ImportantCustomer.h"
#import "UserManageViewController.h"

@implementation UserManageBaseViewModel

#pragma mark - Delegate NetworkingBaseManagerAPISuccessCallbackDelegate
- (void)manager:(NetworkingBaseManager *)manager callAPIDidSuccessWithParams:(NSDictionary *)responseParams{
    
    NSDictionary *dataDic = [responseParams objectForKey:@"data"];
    UserManage *userManager = [UserManage mj_objectWithKeyValues:dataDic];
    UserManageViewController *userManageViewController = (UserManageViewController *)self.viewObject;
    userManageViewController.userManage = userManager;
    
    if (self.finishBlock) {
        self.finishBlock();
    }
    
}
/*
 
 1、获取客户
 Path:/projects/%ld/salers/%ld/users
 HTTP Method:GET
 URL Params:
 Request Headers:{“Content-Type”:”application/json;charset=utf-8”, ”token”:”密匙(sha256加盐)”, “timestamp”:”时间戳”}
 Request Body:
 Response Body:{
	“stateCode”:标识(Integer)，
	“stateMessage”:消息(String),
	“data”:{
 importantCustomer:[
 {
 “userId”:用户id(Integer),
 “avatar”:用户头像(String),
 “lastLoginTime”:上次登录时间(String),
 “nickName”:用户昵称(String),
 “sex”:性别(Integer, 0女，1男，3未设定)，
 “occupation”:职业(String),
 “AppointmentInfomation”:预约看房信息[{
 “houseNumber”：房屋编号(String),
 “name”:看房人姓名(String),
 “date”：看房日期(String),
 “phoneNumber”:手机号(String),
 “amount”:看房人数(Integer),
 “remark”:备注(String)
 }]
 “continueLoginTimes”:连续登录天数(Integer)，
 “signTimes”:当前项目签到天数(Integer)，
 “activities”:当前参加活动[{
 “activityType”:活动类型(String)，
 “activityName”:活动名称(String),
 }, {}, {}......]
 “attentionedLayouts”:[户型名称]([String]),
 “visitHistories”:[访问历史纪录{
 “visitTime”:访问时间(String),
 “register”:登记人(String)
 }],
 }
 ]
 
 commonCustomer:[
 {
 “userId”:用户id(Integer),
 “avatar”:用户头像(String),
 “lastLoginTime”:上次登录时间(String),
 “nickName”:用户昵称(String),
 “sex”:性别(Integer, 0女，1男，3未设定)，
 “occupation”:职业(String),
 “AppointmentInfomation”:预约看房信息{
 “houseNumber”：房屋编号(String),
 “name”:看房人姓名(String),
 “date”：看房日期(String),
 “phoneNumber”:手机号(String),
 “number”:看房人数(Integer),
 “remark”:备注(String)
 }
 “continueLoginTimes”:连续登录天数(Integer)，
 “continueSignTimes”:当前项目签到天数(Integer)，
 “activities”:当前参加活动{
 “activityType”:活动类型(Integer)，
 “activityIntroduction”:活动简介(String),
 }
 “attentionedLayouts”:[户型名称]([String]),
 “visitHistories”:[访问历史纪录{
 “date”:访问时间(String),
 “register”:登记人(String)
 }],
 }
 ]
	}
 }

 
 
 */
#pragma mark - Public
-(void)loadRequest{
    self.manager = [NetworkingManagerFactory generateSHA256Manager];
    self.manager.apiName = [[RequestGenerator sharedInstance] generateCommonApiWithName:[NSString stringWithFormat:@"projects/%ld/salers/%ld/users", [AppContext sharedInstance].projectId,[AppContext sharedInstance].userId]];
    self.manager.requestType = HTTP_GET;
    self.manager.successDelegate = self;
    self.manager.validator = self;
    [self.manager loadRequest];
}

- (void)setUpMJModel{
    [UserManage mj_setupObjectClassInArray:^NSDictionary *{
        return @{
                 @"commonCustomerArray":@"commonCustomer",
                 @"importantCustomerArray":@"importantCustomer"
                 };
    }];
    
    [CommonCustomer mj_setupObjectClassInArray:^NSDictionary *{
        return @{
                 @"activitiesArray":@"activities",
                 @"appointmentInfomationArray":@"appointmentInfomation",
                 @"attentionedLayoutsArray":@"attentionedLayouts",
                 @"visitHistoriesArray":@"visitHistories"
                 };
    }];
    
    [ImportantCustomer mj_setupObjectClassInArray:^NSDictionary *{
        return @{
                 @"activitiesArray":@"activities",
                 @"appointmentInfomationArray":@"appointmentInfomation",
                 @"attentionedLayoutsArray":@"attentionedLayouts",
                 @"visitHistoriesArray":@"visitHistories"
                 };
    }];

}

@end
